﻿using HY.Common;
using HY.Entity;
using HY.Service;
using HY.Web.Controllers;
using HY.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace HY.Web.Areas.Monitor.Controllers
{
    public class EquipmentTypeController : BaseController
    {
        BaseService service = new BaseService();
        // GET: Monitor/EquipmentType
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Index(int page, int limit)
        {
            ReturnModel returnModel = new ReturnModel();
            try
            {
                var typeName = Request.Form["typeName"];
                Expression<Func<EquipmentType, bool>> where = (m => m.IsDeleted == false);
                if (!string.IsNullOrWhiteSpace(typeName))
                    where = where.And(m => m.TypeName.Contains(typeName));
                var tuple = service.EFGetPageList(where, page, limit, o => o.CreateDate, false);
                returnModel = base.GetReturnModel(tuple.Item1, tuple.Item2);
            }
            catch (Exception ex)
            {
                returnModel = base.GetReturnModel(ex);
                LogHelper.Error("查询设备分类列表", ex);
            }
            return Json(returnModel);
        }
    }
}